package com.batchOperation.test;

/**
 * @Package: com.batchOperation.test
 * @ClassName: EasyExcelMultiSheet
 * @Author: h2cloud
 * @CreateTime: 2024/7/18 10:55 下午
 * @Description:
 */

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;

import java.util.ArrayList;
import java.util.List;

public class EasyExcelMultiSheet {

	public static void main(String[] args) {
		// 创建空数据列表
		List<DemoData1> emptyData1 = new ArrayList<>();
		List<DemoData2> emptyData2 = new ArrayList<>();

		// 文件名
		String fileName = "/Users/h2cloud/javaproject/javaStudy/src/main/java/com/batchOperation/test/multiSheet.xlsx";

		// 创建 Excel 文件并写入多个 sheet
		try (ExcelWriter excelWriter = EasyExcel.write(fileName).build()) {
			// 创建第一个 sheet 只写入表头
			WriteSheet sheet1 = EasyExcel.writerSheet(0, "Sheet1").head(DemoData1.class).build();
			excelWriter.write(emptyData1, sheet1);

			// 创建第二个 sheet 只写入表头
			WriteSheet sheet2 = EasyExcel.writerSheet(1, "Sheet2").head(DemoData2.class).build();
			excelWriter.write(emptyData2, sheet2);
		}
	}
}

